/*********************/
/** PreBuiltAtagManager.java */
/*********************/
package atag.apps.mainApp;

import atag.common.*;
import atag.runtime.*;
import atag.runtime.ln.*;
import atag.runtime.ln.neighborhoodDefs.*;

public class PreBuiltAtagManager extends AtagManager {

	public PreBuiltAtagManager() {
		
	}

	public void setUp() {
		taskDecls.addElement(new RunnableTask((ATaGTaskDeclaration) this.m_program.getTaskList().elementAt(0),new SenseLight(this.m_dataPool, this.m_config),
				Thread.MAX_PRIORITY - 0));
		taskDecls.addElement(new RunnableTask((ATaGTaskDeclaration) this.m_program.getTaskList().elementAt(1),new ActuateLight(this.m_dataPool, this.m_config),
				Thread.MAX_PRIORITY - 0));
		taskDecls.addElement(new RunnableTask((ATaGTaskDeclaration) this.m_program.getTaskList().elementAt(2),new SenseRFID(this.m_dataPool, this.m_config),
				Thread.MAX_PRIORITY - 0));
		taskDecls.addElement(new RunnableTask((ATaGTaskDeclaration) this.m_program.getTaskList().elementAt(3),new ProcessLightInfo(this.m_dataPool, this.m_config),
				Thread.MAX_PRIORITY - 0));
		taskDecls.addElement(new RunnableTask((ATaGTaskDeclaration) this.m_program.getTaskList().elementAt(4),new ProcessRFID(this.m_dataPool, this.m_config),
				Thread.MAX_PRIORITY - 0));
		taskDecls.addElement(new RunnableTask((ATaGTaskDeclaration) this.m_program.getTaskList().elementAt(5),new ControlLightSetting(this.m_dataPool, this.m_config),
				Thread.MAX_PRIORITY - 0));
		taskDecls.addElement(new RunnableTask((ATaGTaskDeclaration) this.m_program.getTaskList().elementAt(6),new Authenticate(this.m_dataPool, this.m_config),
				Thread.MAX_PRIORITY - 0));
	}

	public Neighborhood[] getLNScopeForData(int taskID, int dataID) {

		switch (dataID) {

			case IDConstants.D_LIGHTREADING:{
				// create a holder for the Scopes
				Predicate[] tempPred0 = new Predicate[3];
				int count0 = 0;

				tempPred0[count0++] = new StringSetMembershipPredicate(
						String.valueOf(IDConstants.T_PROCESSLIGHTINFO),
						StringSetMembershipPredicate.IS_IN,
						NodeInfo.ASSIGNED_TASK_ATTR_NAME);

				tempPred0[count0++] = new IntegerSimplePredicate("Room",
						IntegerSimplePredicate.EQUAL,
						((Integer) m_config.getAttributeByName("Room")).intValue());
				Predicate[] finalPred0 = new Predicate[count0];
				for(int i = 0; i < count0; i++){
					finalPred0[i] = tempPred0[i];
				}
				Neighborhood scopeOfChannel0 = new ConjunctiveNeighborhood(finalPred0);


				return new Neighborhood[] { 
					scopeOfChannel0
					};

			}
			case IDConstants.D_ACTION:{
				// create a holder for the Scopes
				Predicate[] tempPred0 = new Predicate[3];
				int count0 = 0;

				tempPred0[count0++] = new StringSetMembershipPredicate(
						String.valueOf(IDConstants.T_ACTUATELIGHT),
						StringSetMembershipPredicate.IS_IN,
						NodeInfo.ASSIGNED_TASK_ATTR_NAME);

				tempPred0[count0++] = new IntegerSimplePredicate("Room",
						IntegerSimplePredicate.EQUAL,
						((Integer) m_config.getAttributeByName("Room")).intValue());

				Predicate[] finalPred0 = new Predicate[count0];
				for(int i = 0; i < count0; i++){
					finalPred0[i] = tempPred0[i];
				}
				Neighborhood scopeOfChannel0 = new ConjunctiveNeighborhood(finalPred0);


				return new Neighborhood[] { 
					scopeOfChannel0
					};

			}
			case IDConstants.D_RFIDLIGHTSETTING:{
				// create a holder for the Scopes
				Predicate[] tempPred0 = new Predicate[3];
				int count0 = 0;

				tempPred0[count0++] = new StringSetMembershipPredicate(
						String.valueOf(IDConstants.T_PROCESSLIGHTINFO),
						StringSetMembershipPredicate.IS_IN,
						NodeInfo.ASSIGNED_TASK_ATTR_NAME);

				tempPred0[count0++] = new IntegerSimplePredicate("Room",
						IntegerSimplePredicate.EQUAL,
						((Integer) m_config.getAttributeByName("Room")).intValue());
				Predicate[] finalPred0 = new Predicate[count0];
				for(int i = 0; i < count0; i++){
					finalPred0[i] = tempPred0[i];
				}
				Neighborhood scopeOfChannel0 = new ConjunctiveNeighborhood(finalPred0);


				return new Neighborhood[] { 
					scopeOfChannel0
					};

			}
			case IDConstants.D_CONTROLLERLIGHTSETTING:{
				throw new IllegalStateException("Need to supply partition info with custom scopes");
			}
			case IDConstants.D_RFID:{
				// create a holder for the Scopes
				Predicate[] tempPred0 = new Predicate[3];
				int count0 = 0;

				tempPred0[count0++] = new StringSetMembershipPredicate(
						String.valueOf(IDConstants.T_PROCESSRFID),
						StringSetMembershipPredicate.IS_IN,
						NodeInfo.ASSIGNED_TASK_ATTR_NAME);

				Predicate[] finalPred0 = new Predicate[count0];
				for(int i = 0; i < count0; i++){
					finalPred0[i] = tempPred0[i];
				}
				Neighborhood scopeOfChannel0 = new ConjunctiveNeighborhood(finalPred0);


				return new Neighborhood[] { 
					scopeOfChannel0
					};

			}
			case IDConstants.D_LIGHTINFOREQUEST:{
				throw new IllegalStateException("Need to supply partition info with custom scopes");
			}
			case IDConstants.D_LIGHTINFORESPONSE:{
				throw new IllegalStateException("Need to supply partition info with custom scopes");
			}
			default:
				return new Neighborhood[] {};
		}/*end switch*/
	}
	public Neighborhood[] getLNScopeForData(int taskID, int dataID,String partitionLabel,int partitionValue) {

		switch (dataID) {

			case IDConstants.D_LIGHTREADING:{
				throw new IllegalStateException("Can supply partition info only with custom scopes");
			}
			case IDConstants.D_ACTION:{
				throw new IllegalStateException("Can supply partition info only with custom scopes");
			}
			case IDConstants.D_RFIDLIGHTSETTING:{
				throw new IllegalStateException("Can supply partition info only with custom scopes");
			}
			case IDConstants.D_CONTROLLERLIGHTSETTING:{
				// create a holder for the Scopes
				Predicate[] tempPred0 = new Predicate[3];
				int count0 = 0;

				tempPred0[count0++] = new StringSetMembershipPredicate(
						String.valueOf(IDConstants.T_PROCESSLIGHTINFO),
						StringSetMembershipPredicate.IS_IN,
						NodeInfo.ASSIGNED_TASK_ATTR_NAME);

				tempPred0[count0++] = new IntegerSimplePredicate(
						partitionLabel,
						IntegerSimplePredicate.EQUAL,
						partitionValue);

				Predicate[] finalPred0 = new Predicate[count0];
				for(int i = 0; i < count0; i++){
					finalPred0[i] = tempPred0[i];
				}
				Neighborhood scopeOfChannel0 = new ConjunctiveNeighborhood(finalPred0);


				return new Neighborhood[] { 
					scopeOfChannel0
					};

			}
			case IDConstants.D_RFID:{
				throw new IllegalStateException("Can supply partition info only with custom scopes");
			}
			case IDConstants.D_LIGHTINFOREQUEST:{
				// create a holder for the Scopes
				Predicate[] tempPred0 = new Predicate[3];
				int count0 = 0;

				tempPred0[count0++] = new StringSetMembershipPredicate(
						String.valueOf(IDConstants.T_PROCESSLIGHTINFO),
						StringSetMembershipPredicate.IS_IN,
						NodeInfo.ASSIGNED_TASK_ATTR_NAME);

				tempPred0[count0++] = new IntegerSimplePredicate(
						partitionLabel,
						IntegerSimplePredicate.EQUAL,
						partitionValue);

				Predicate[] finalPred0 = new Predicate[count0];
				for(int i = 0; i < count0; i++){
					finalPred0[i] = tempPred0[i];
				}
				Neighborhood scopeOfChannel0 = new ConjunctiveNeighborhood(finalPred0);


				return new Neighborhood[] { 
					scopeOfChannel0
					};

			}
			case IDConstants.D_LIGHTINFORESPONSE:{
				// create a holder for the Scopes
				Predicate[] tempPred0 = new Predicate[3];
				int count0 = 0;

				tempPred0[count0++] = new StringSetMembershipPredicate(
						String.valueOf(IDConstants.T_CONTROLLIGHTSETTING),
						StringSetMembershipPredicate.IS_IN,
						NodeInfo.ASSIGNED_TASK_ATTR_NAME);

				tempPred0[count0++] = new IntegerSimplePredicate(
						partitionLabel,
						IntegerSimplePredicate.EQUAL,
						partitionValue);

				Predicate[] finalPred0 = new Predicate[count0];
				for(int i = 0; i < count0; i++){
					finalPred0[i] = tempPred0[i];
				}
				Neighborhood scopeOfChannel0 = new ConjunctiveNeighborhood(finalPred0);


				return new Neighborhood[] { 
					scopeOfChannel0
					};

			}
			default:
				return new Neighborhood[] {};
		}/*end switch*/
	}
}